package cse.luanvan;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

public class WebService {
	
	final String NAMESPACE = "http://bando24h.com/";
    String METHOD_NAME = "GetLatLog";    
    String SOAP_ACTION = "http://bando24h.com/GetLatLog";
    final String URL = "http://bando24h.com/WebService.asmx";
  //  final String URL ="http://10.0.2.2:30754/WebService.asmx";

    
    private String address;
    private double lat,lon,km;
    private int kieudv;
    private String dichvu;
    
    
	
    
	public WebService() {
		super();
		// TODO Auto-generated constructor stub
	}


	public WebService(String _address) {
		super();
		this.address= _address;
		
	}
	


	public WebService(double lat, double lon, double km, int kieudv, String dv) {
		super();
		this.lat = lat;
		this.lon = lon;
		this.km = km;
		this.kieudv = kieudv;
		this.dichvu = dv;
	}
	public String getService(){
		 try{
			 String query=String.valueOf(lat)+"_"+String.valueOf(lon)+"_"+String.valueOf(kieudv)+"_"+dichvu+"_"+String.valueOf(km);
			 METHOD_NAME = "GetService";
			 SOAP_ACTION = "http://bando24h.com/GetService";
	        	SoapObject request=new SoapObject(NAMESPACE, METHOD_NAME);
	        	request.addProperty("paras", query);
//	        	request.addAttribute("lon",lon );
//	        	request.addAttribute("kieudichvu",kieudv );
//	        	request.addAttribute("dichvu",dv );
//	        	request.addAttribute("km", km);
	        	///request.addProperty("district", districtName);
	        	SoapSerializationEnvelope evenlop=new SoapSerializationEnvelope(SoapEnvelope.VER11);
	        	evenlop.dotNet=true;
	        	evenlop.setOutputSoapObject(request);
	        	
	        	HttpTransportSE androidHttpTransport=new HttpTransportSE(URL);
	        	androidHttpTransport.call(SOAP_ACTION, evenlop);
	        	SoapPrimitive reponse = (SoapPrimitive) evenlop.getResponse();
	        	if(reponse!=null)
	        		return reponse.toString();
	        	return null;
	        	
	        	
	        }
	        catch(Exception e){
	        	return null;
	        }
	}
	

	public String getLatLong(){
		
        try{
        	SoapObject request=new SoapObject(NAMESPACE, METHOD_NAME);
        	request.addProperty("address", address);
        	///request.addProperty("district", districtName);
        	SoapSerializationEnvelope evenlop=new SoapSerializationEnvelope(SoapEnvelope.VER11);
        	evenlop.dotNet=true;
        	evenlop.setOutputSoapObject(request);
        	
        	HttpTransportSE androidHttpTransport=new HttpTransportSE(URL);
        	androidHttpTransport.call(SOAP_ACTION, evenlop);
        	SoapPrimitive reponse = (SoapPrimitive) evenlop.getResponse();
        	if(reponse!=null)
        		return reponse.toString();
        	return null;
        	
        }
        catch(Exception e){
        	return null;
        }
	}
	public String getServiceEntertain(double lat,double lon,int dichvu){
		 String METHOD_NAME = "GetServiceEntertain";    
		    String SOAP_ACTION = "http://bando24h.com/GetServiceEntertain";
		try{
			String param=String.valueOf(lat)+"_"+String.valueOf(lon)+"_"+String.valueOf(dichvu);
        	SoapObject request=new SoapObject(NAMESPACE, METHOD_NAME);
        	request.addProperty("paras", param);
        	///request.addProperty("district", districtName);
        	SoapSerializationEnvelope evenlop=new SoapSerializationEnvelope(SoapEnvelope.VER11);
        	evenlop.dotNet=true;
        	evenlop.setOutputSoapObject(request);
        	
        	HttpTransportSE androidHttpTransport=new HttpTransportSE(URL);
        	androidHttpTransport.call(SOAP_ACTION, evenlop);
        	SoapPrimitive reponse = (SoapPrimitive) evenlop.getResponse();
        	if(reponse!=null)
        		return reponse.toString();
        	return null;
        	
        }
        catch(Exception e){
        	return null;
        }
	}
}
